using Microsoft.Extensions.DependencyInjection;

using NUnit.Framework;

using System;

namespace DependencyInjectionTest
{
    public class Tests
    {
        [SetUp]
        public void Setup()
        {
        }

        [Test]
        public void Test1()
        {

            ServiceCollection services = new();
            services.AddSingleton<Demo1, Demo1>();
            var serviceProvider = services.BuildServiceProvider();
            var demo1 = serviceProvider.GetRequiredService<Demo1>();
            Assert.IsNotNull(demo1);

            services.AddSingleton<Demo2, Demo2>();
            var demo1_2 = serviceProvider.GetRequiredService<Demo1>();
            Assert.IsNotNull(demo1_2);
            Assert.AreEqual(demo1, demo1_2);

            var provider = services.BuildServiceProvider();
            demo1_2 = serviceProvider.GetRequiredService<Demo1>();
            Assert.IsNotNull(demo1_2);
            Assert.AreEqual(demo1, demo1_2);

            //var demo2 = provider.GetRequiredService<Demo2>();
            //Assert.IsNotNull(demo2);
            //var demo2_2 = provider.GetRequiredService<Demo2>();
            //Assert.AreNotEqual(demo2, demo2_2);

            Console.WriteLine(Gaf.AddinPackageFormat.Lite | Gaf.AddinPackageFormat.Directory);

        }
    }

    public class Demo1
    {
        static int _seed = 0;

        public int Id { get; }

        public Demo1()
        {
            _seed++;
            Id = _seed;
        }
    }

    public class Demo2
    {

    }
}